package com.neuedu.common;

import com.fasterxml.jackson.annotation.JsonInclude;

import java.io.Serializable;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class JSONData<T> implements Serializable {
    //状态码 0：成功 1：处理中 -1：失败
    private Integer code;
    //描述信息
    private String msg;
    //数据
    private T data;

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    private JSONData(Integer code,T data ,String msg){
        this.code = code;
        this.data = data;
        this.msg = msg;
    }

    //成功
    public static JSONData buildSuccess(){
        return new JSONData(0,null,null);
    }
    //成功 传输描述信息
    public static JSONData buildSuccess(String msg){
        return new JSONData(0,null,msg);
    }
    //成功 传输 数据
    public static<T> JSONData<T> buildSuccess(T data){
        return new JSONData(0,data,null);
    }
    //成功 传输 数据 传输描述信息
    public static<T> JSONData<T> buildSuccess(T data,String msg){
        return new JSONData(0,data,msg);
    }
    //失败
    public static JSONData buildError(){
        return new JSONData(-1,null,null);
    }
    //失败 描述信息
    public static JSONData buildError(String msg){
        return new JSONData(-1,null,msg);
    }
    //失败 状态码 描述信息
    public static JSONData buildError(Integer code,String msg){
        return new JSONData(code,null,msg);
    }

    @Override
    public String toString() {
        return "JSONData{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                '}';
    }
}
